package com.code2roc.fastface.config;

import com.code2roc.fastface.db.MapperBeanManage;
import com.code2roc.fastface.util.DataBaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class StartUpContext  implements ApplicationRunner {
    @Autowired
    private ApplicationContext context;
    @Autowired
    private MapperBeanManage mapperBeanManage;
    @Autowired
    private DataBaseUtil dataBaseUtil;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        Map<String, Object> annotatedBeans = context.getBeansWithAnnotation(SpringBootApplication.class);
        List<Class> bootClassList = new ArrayList<>();
        for (String key:annotatedBeans.keySet()) {
            bootClassList.add(annotatedBeans.get(key).getClass());
        }
        mapperBeanManage.initMapperBean(bootClassList);
        dataBaseUtil.init();
    }
}
